package cn.bonoon.controllers.comment;

import cn.bonoon.kernel.support.entities.Persistable;
import cn.bonoon.kernel.support.services.SearchService;
import cn.bonoon.kernel.web.controllers.BaseButtonResolver;
import cn.bonoon.kernel.web.controllers.GridButtonResolver;
import cn.bonoon.kernel.web.handlers.DialogGridHandler;
import cn.bonoon.kernel.web.handlers.HandlerRegister;
import cn.bonoon.kernel.web.html.grid.StandardGridBuilder;

public class CommentDialog<E extends Persistable> extends DialogGridHandler<E>{

	public CommentDialog(HandlerRegister register, SearchService<E> service) throws Exception {
		this(register, service, "commented.id");
	}
	
	public CommentDialog(HandlerRegister register, SearchService<E> service, String relatedKey) throws Exception {
		super(register, service, CommentItem.class);
		this.relatedKey = relatedKey;
	}
	
	@Override
	protected void register(BaseButtonResolver resolver, StandardGridBuilder builder) throws Exception {
		set("详细评论信息", true);
		size(660, 480);
		resolver.setName("查看评论");
		super.register(resolver, builder);	
	}
	
	public static <P extends Persistable> GridButtonResolver button(HandlerRegister register, SearchService<P> service) throws Exception{
		CommentDialog<P> cd = new CommentDialog<P>(register, service);
		GridButtonResolver gbr = register.button();
		cd.register(gbr);
		return gbr;
	}
	
	public static <P extends Persistable> GridButtonResolver button(HandlerRegister register, SearchService<P> service, String relatedKey) throws Exception{
		CommentDialog<P> cd = new CommentDialog<P>(register, service, relatedKey);
		GridButtonResolver gbr = register.button();
		cd.register(gbr);
		return gbr;
	}
}
